function PLCCom()
	
	-- 描述: 从PLC端读取对应的点位信息,并赋值到GString()中(根据实际情况自行修改)
	-- 输入: 无
	-- 输出: Stt 返回值(0为读取成功)
	function ReadLoc()
		local templocstr = ""
		local locstr = ""
		
		Stt, DReadLocWord = ReadBatchRegisters(true,"D",4300,72)
		
		if Stt == 0 then
			for ii = 1,72,4 do
				templocstr = ""
				locstr = ""
				for ij = 0,3 do
					DReadLocWord[ii+ij] = DReadLocWord[ii+ij]/1000
					templocstr = tostring(DReadLocWord[ii+ij])
					locstr = locstr..templocstr..","
				end
				GString[(ii-1)/4+1] = locstr
				print(GString[(ii-1)/4+1])
			end
		else	
			return Stt
		end
		
		Stt, DReadRollWord = ReadBatchRegisters(true,"D",4426,1)
		if Stt == 0 then
			GDouble[29] = DReadRollWord[1]/1000
		else
			return Stt
		end
		
		Stt, DReadRollWord = ReadBatchRegisters(true,"D",4434,1)
		if Stt == 0 then
			GDouble[30] = DReadRollWord[1]/1000
		else
			return Stt
		end
		
		return Stt
	end
	
	
	print("PLCCom Thread Start!!!")
	
	bHeardBeat = false
	HeartBeatCount = 0
	
	::Reconnect::
	PLC_Stt = Connect("192.168.3.106",1025) 
	if PLC_Stt ~= 0 then
		--输出报警信号
		GDouble[3] = PLC_Stt
		IO.Set(DO_ALARM,1)
		
		DisConnect()
		Thread.Sleep(2)
		goto Reconnect
	end
	
	print("Connect PLC Successfully!")
	
	while true do
		
		-- 读取点位
		if  GInt[10] ==  1 then
			print("进行点位读取!!!")
			Stt = ReadLoc()
			if Stt ~= 0 then
				GInt[10] = -1
				print("进行点位读取失败!!!")
				-- 输出报警信号
				GDouble[3] = -20000
				IO.Set(DO_ALARM,1)

				DisConnect()
				goto Reconnect
			else
				GInt[10] = 0
				print("进行点位读取成功!!!")
			end
		end
	
		-- 手动模式 & 自动模式(写入)
		
		-- 位地址
		-----------------------------------------
		-- 直接运动中		M2400		 GBool[23]
		-- 正在读取点位		M2401
		-- 上电状态			M2402	     GBool[22]
		-- 心跳包			M2403
		-----------------------------------------
		-- 处理并写入位地址
		CoilsWrite = {}
		
		CoilsWrite[1] = GBool[23]
		CoilsWrite[2] = false
		CoilsWrite[3] = GBool[22]
	
		if bHeardBeat == false then
			HeartBeatCount = HeartBeatCount + 1
			if HeartBeatCount == 10 then
				bHeardBeat = true
				HeartBeatCount = 0
			end
		else 
			HeartBeatCount = HeartBeatCount + 1
			if HeartBeatCount == 10 then
				bHeardBeat = false
				HeartBeatCount = 0
			end
		end
		CoilsWrite[4] = bHeardBeat
		
		Stt = WriteBatchCoils("M",2400,4,CoilsWrite)
	
		if Stt ~= 0 then
			-- 输出报警信号
			GDouble[3] = Stt
			IO.Set(DO_ALARM,1)

			DisConnect()
			goto Reconnect
		end
    
		-- 双字地址
		-----------------------------------------
		-- 当前位置X	  D4008-D4009	  GDouble[5]
		-- 当前位置Y	  D4010-D4011	  GDouble[6]
		-- 当前位置Z	  D4012-D4013	  GDouble[7]
		-- 当前位置A	  D4014-D4015	  GDouble[8]
		-- 当前位置J1	  D4016-D4017	  GDouble[9]
		-- 当前位置J2	  D4018-D4019	  GDouble[10]
		-- 当前位置J3	  D4020-D4021	  GDouble[11]
		-- 当前位置J4	  D4022-D4023	  GDouble[12]
		-----------------------------------------
		-- 处理并写入双字地址(当前X,Y,Z,Roll以及J1,J2,J3,J4)
		DWordsWrite = {}

		for ii = 1,8 do
			DWordsWrite[ii] = GDouble[ii+4]
		end

		Stt = WriteBatchRegisters(true,"D",4008,8,DWordsWrite)
		if Stt ~= 0 then
			-- 输出报警信号
			GDouble[3] = Stt
			IO.Set(DO_ALARM,1)

			DisConnect()
			goto Reconnect
		end
    
		-- 双字地址
		-----------------------------------------
		-- 当前坐标系	      	  D4000	      GDouble[1]
		-- 当前速度	  	      	  D4002	      GDouble[2]
		-- 故障代码	      		  D4004	      GDouble[3]
		-- 当前直接运动模式		  D4006		  GDouble[4]
		-----------------------------------------
		-- 处理并写入单字地址(当前速度,当前坐标系,故障代码,当前模式)
		SWordWrite = {}

		for ii =1,4 do
			SWordWrite[ii] = GDouble[ii]
		end
		
		Stt = WriteBatchRegisters(true,"D",4000,4,SWordWrite)
		if Stt ~= 0 then
			-- 输出报警信号
			GDouble[3] = Stt
			IO.Set(DO_ALARM,1)

			DisConnect()
			goto Reconnect
		end
    
		-- 手动模式 & 自动模式(读取)

		-- 位地址
		--------------------------------------
		-- 手动与自动状态		M2500	  GBool[1]
		-- 上电/下电(开关)		M2501	  GBool[2]
		--------------------------------------
		Stt, CoilsRead = ReadBatchCoils("M",2500,2)
		if Stt ~= 0 then
			-- 输出报警信号
			GDouble[3] = Stt
			IO.Set(DO_ALARM,1)

			DisConnect()
			goto Reconnect
		end

		for ii=1,2 do
			GBool[ii] =  CoilsRead[ii]
		end

		-- 双字地址
		--------------------------------------
		-- 速度设置			D4210	  GDouble[27]
		-- 下降速度设置		D4212	  GDouble[28]
		--------------------------------------
		Stt, SWordRead = ReadBatchRegisters(true,"D",4210,2)

		if Stt ~= 0 then
			-- 输出报警信号
			GDouble[3] = Stt
			IO.Set(DO_ALARM,1)

			DisConnect()
			goto Reconnect
		end
		
		for ii = 1,2 do
			GDouble[26+ii] = SWordRead[ii]
		end
		
		-- 手动模式下读写地址

		-- (根据GBool[1]判断当前处于模式,不同模式下读写不同地址,节省通讯交互时间)
		if GBool[1] == true then

			-- 手动模式(读取)

			-- 位地址
			--------------------------------------
			--J1/X+						    M2502	  GBool[3]
			--J2/Y+						    M2503	  GBool[4]
			--J3/Z+						    M2504	  GBool[5]
			--J4/A+						    M2505	  GBool[6]
			--J1/X-						    M2506	  GBool[7]
			--J2/Y-						    M2507	  GBool[8]
			--J3/Z-						    M2508	  GBool[9]
			--J4/A-						    M2509	  GBool[10]
			--运动到目标点(按钮)			M2510	  GBool[11]
			--读取点位						M2511	  GBool[12]
			--------------------------------------
			Stt, CoilsRead = ReadBatchCoils("M",2502,10)
			if Stt ~= 0 then
				-- 输出报警信号
				GDouble[3] = Stt
				IO.Set(DO_ALARM,1)

				DisConnect()
				goto Reconnect
			end

			for ii=1, 10 do
				GBool[ii+2] =  CoilsRead[ii]
			end

			-- 双字地址
			-----------------------------------------------------------------
			--示教方式选择（0：连续示教、1：寸动示教）	 D4200    GDouble[21]
			--寸动关节步长								 D4202    GDouble[22]
			--寸动线性步长								 D4204    GDouble[23]
			--直接运动模式（1直线、2关节）(预留)		 D4206    GDouble[24]
			--坐标系选择（1关节、2直角）				 D4208    GDouble[25]
			--运动点序号								 D4214    GDouble[26]
			-------------------------------------------------------------------
			Stt, SWordRead = ReadBatchRegisters(true,"D",4200,8)
			if Stt ~= 0 then
				-- 输出报警信号
				GDouble[3]= Stt
				IO.Set(DO_ALARM,1)

				DisConnect()
				goto Reconnect
			end
			for ii=1,5 do
				GDouble[ii+20] = SWordRead[ii]
			end
			
			-- 反馈当前坐标系到PLC
			GDouble[1] = GDouble[25]
			
			-- 反馈当前直接运动模式到PLC
			GDouble[4]= GDouble[24]
			
			-- 读取运动点位序号
			GDouble[26] = SWordRead[8]
      
			-- 手动模式下加载需要移动的目标点位
			-----------------------------------------
			-- 点位序号为1的点位
			-- 当前位置X	  D4300-D4301
			-- 当前位置Y	  D4302-D4303
			-- 当前位置Z	  D4304-D4305
			-- 当前位置A	  D4306-D4307
			-- 点位序号为2的点位
			-- 当前位置X	  D4308-D4309
			-- 当前位置Y	  D4310-D4311
			-- 当前位置Z	  D4312-D4313
			-- 当前位置A	  D4314-D4315
			-- ......
			-----------------------------------------
			-- 机器人处于手动模式(GBool[1]为true),读取目标点位信号为true(GBool[32]为true),选择的点位在规定的范围内,进行点位读取.
			selectPos = GDouble(26)
			if GBool[1] == true and GBool[32] == true and selectPos > 0 and selectPos <=  GInt[1] then
				PosAddr = 4300 + 8*(selectPos - 1)

				-- 由于计算之后,PosAddr保留小数点后一位,需要转换回整数
				PosAddr = math.modf(PosAddr)

				Stt, DWordsRead = ReadBatchRegisters(true,"D",PosAddr,4)
				if Stt == 0 then
					posLoc = tostring(DWordsRead[1]) ..",".. tostring(DWordsRead[2]) ..",".. tostring(DWordsRead[3]) ..",".. tostring(DWordsRead[4]) 
			  
					print("手动模式下:读取移动的目标点成功")
			  
					-- 读取成功
					GString[26] = posLoc
					GBool[33] = true
				else

					print("手动模式下:读取移动的目标点失败")
			  
					-- 读取失败
					GString[26] = ""
					GBool[33] = false
				end 

				GBool[32] = false
			end

			-- 自动模式下读写地址

		-- (根据GBool[1]判断当前处于模式,不同模式下读写不同地址,节省通讯交互时间)
		else
			
			

		end

	end
	
	
end